package com.woniuxy.caradmin.controller;


import com.woniuxy.caradmin.entity.pojo.Dictionary;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.DictionaryService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.woniuxy.caradmin.entity.pojo.Dictionary;
import com.woniuxy.caradmin.exception.CarException;
import com.woniuxy.caradmin.service.DictionaryService;
import com.woniuxy.caradmin.util.Constaint;
import com.woniuxy.caradmin.util.R;
import com.woniuxy.caradmin.util.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.CacheRequest;
import java.util.List;

import java.util.List;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author womenzu
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {
    @Autowired
    private DictionaryService dictionaryService;

@GetMapping("/dictionaryType12")
    public R selectAllByType12(){
    List<Dictionary> dictionaryList = dictionaryService.selectBytype12();
    if (dictionaryList != null && dictionaryList.size()>0){
        //引入正确的部门正确码
       return R.ok().data("dictionaryList",dictionaryList);
    }else {
        throw  new CarException(ResultCode.DBREAKISNULL, Constaint.DBREAKISNULL);
    }
}
    @GetMapping("/dictionaryType13")
    @ApiOperation(value = "获取违章项目")
    public R selectAllByType13(){
        List<Dictionary> dictionaryList = dictionaryService.selectBytype13();
        if (dictionaryList != null && dictionaryList.size()>0){
            //引入正确的部门正确码
            return R.ok().data("dictionaryList",dictionaryList);
        }else {
            throw  new CarException(ResultCode.DYEARISNULL, Constaint.DYEARISNULL);
        }
    }

    @GetMapping("/dictionaryType14")
    @ApiOperation(value = "获取保险种类")
    public R selectAllByType14(){
        List<Dictionary> dictionaryList = dictionaryService.selectBytype14();
        if (dictionaryList != null && dictionaryList.size()>0){
            //引入正确的部门正确码
            return R.ok().data("dictionaryList",dictionaryList);
        }else {
            throw  new CarException(ResultCode.DYEARISNULL, Constaint.DYEARISNULL);
        }
    }

    @GetMapping("/dictionaryType15")
    @ApiOperation(value = "获取保险公司")
    public R selectAllByType15(){
        List<Dictionary> dictionaryList = dictionaryService.selectBytype15();
        if (dictionaryList != null && dictionaryList.size()>0){
            //引入正确的部门正确码
            return R.ok().data("dictionaryList",dictionaryList);
        }else {
            throw  new CarException(ResultCode.DYEARISNULL, Constaint.DYEARISNULL);
        }
    }

    @ApiOperation(value = "获取车辆状态")
    @GetMapping(value = "/getCarStatus")
    public R getCarStatus(){
        List<Dictionary> carStatusList = dictionaryService.selectCarStatus();
        if(carStatusList!=null&&carStatusList.size()>0){
            return R.ok().data("carStatusList",carStatusList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation(value = "获取往来单位类型")
    @GetMapping(value = "/getUnitType")
    public R getUnitType(){
        List<Dictionary> unitTypeList = dictionaryService.selectUnitType();
        if(unitTypeList!=null&&unitTypeList.size()>0){
            return R.ok().data("unittypeList",unitTypeList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation(value = "获取车辆品牌")
    @GetMapping(value = "/getbrand")
    public R getbrand(){
        List<Dictionary> carBrandList = dictionaryService.selectCarBrand();
        if(carBrandList!=null&&carBrandList.size()>0){
            return R.ok().data("carBrandList",carBrandList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation(value = "获取车辆级别")
    @GetMapping(value = "/getclazz")
    public R getclazz(){
        List<Dictionary> carClazzList = dictionaryService.selectCarClazz();
        if(carClazzList!=null&&carClazzList.size()>0){
            return R.ok().data("carClazzList",carClazzList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation(value = "获取车辆型号")
    @GetMapping(value = "/gettype")
    public R gettype(){
        List<Dictionary> carTypeList = dictionaryService.selectCarType();
        if(carTypeList!=null&&carTypeList.size()>0){
            return R.ok().data("carTypeList",carTypeList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation(value = "获取车辆颜色")
    @GetMapping(value = "/getcolor")
    public R getcolor(){
        List<Dictionary> carColorList = dictionaryService.selectCarColor();
        if(carColorList!=null&&carColorList.size()>0){
            return R.ok().data("carColorList",carColorList);
        }else{
            throw new CarException(ResultCode.ERROR, Constaint.ERROR);
        }
    }
    @ApiOperation("查询用户职位")
    @GetMapping("/selectEmpByType")
    public R selectEmpByType(){
        List<Dictionary> dictionaries = dictionaryService.selectEmpByType();
        if(dictionaries!=null&&dictionaries.size()>0){
            return R.ok().data("dictionaries",dictionaries);
        }else {
            throw new CarException(ResultCode.EMPISNULL, Constaint.EMPISNULL);
        }
    }
}

